package com.cj.apiserver.controller;

import com.cj.apiserver.model.User;
import com.cj.apiserver.utils.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author cc
 * @date 2025-03-23 14:28
 **/
@RestController
public class HelloController {

    @GetMapping("/hello")
    public void hello(HttpServletRequest request){
        // 传递
        // 参数  和 签名

    }

    @PostMapping("/user")
    public String getUsernameByPost(@RequestBody User user,HttpServletRequest request){
        String accessKey = request.getHeader("accessKey");
        String nonce = request.getHeader("nonce");
        String timestamp = request.getHeader("timestamp");
        String sign = request.getHeader("sign");
        String body = request.getHeader("body");

        // 校验用户
        // 校验时间戳
        // 校验nonce
        // 生成签名并对比
        String serverSign = StringUtils.genSign(body, "abc");
        if (!sign.equals(serverSign)){
            throw new RuntimeException("签名错误");
        }


        return "username is chenjie";
    }
}
